package com.cysion.study.ui.personal

import android.support.v4.app.Fragment
import android.support.v4.content.res.ResourcesCompat
import android.view.View
import com.cysion.other.color
import com.cysion.study.R
import com.cysion.study.helper.FragmentListVals
import com.cysion.study.ktbox.base.BaseActivity
import com.cysion.study.ktbox.base.BaseFragmentAdapter
import com.cysion.study.ktbox.utils.darkTextTheme
import com.cysion.study.ui.fragment.PendingsFragment
import com.cysion.study.uibox.bar.TopBar
import com.cysion.targetfun._addOnPageChangeListener
import kotlinx.android.synthetic.main.activity_myapproval.*
import kotlinx.android.synthetic.main.activity_myapproval.topbar
import kotlinx.android.synthetic.main.activity_myapproval.vp_content
import java.util.*

//我的审批
class MyApprovalActivity : BaseActivity(), View.OnClickListener {



    private lateinit var mFragments: MutableList<Fragment>
    private lateinit var mTitles: MutableList<String>
    override fun getLayoutId(): Int = R.layout.activity_myapproval

    override fun initView() {
        darkTextTheme(color(R.color.white))
        topbar.apply {
            setTitle("我的审批")
            setTitleBackColor(color(R.color.white))
            setOnTopBarClickListener { obj, pos ->
                if (pos == TopBar.Pos.LEFT) {
                    finish()
                }
            }
        }
        tab1.setOnClickListener(this)
        tab2.setOnClickListener(this)
        intab1()
        vp_content.offscreenPageLimit = 2
        mFragments = getApprovalFragments()
        mTitles = FragmentListVals.getApprovalTitles()
        vp_content.adapter = BaseFragmentAdapter(this.supportFragmentManager, mFragments, mTitles)
//        vp_content.addOnPageChangeListener()
        vp_content._addOnPageChangeListener {
            _onPageSelected {
                when (it) {
                    0 -> {
                        intab1()//审批
                        vp_content.currentItem = it
                    }
                    1 -> {
                        vp_content.currentItem = it
                        intab2()//抄送
                    }
                }
            }
        }
    }
    var type = "0"

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.tab1 -> {//
                intab1()
                type = "0"
                vp_content.currentItem = 0
            }
            R.id.tab2 -> {//
                type = "1"
                intab2()
                vp_content.currentItem = 1
            }

        }

    }
    private fun intab1() {
        tab1.background = ResourcesCompat.getDrawable(getResources(), R.drawable.tab1, null)
//        tv_cs.background = ResourcesCompat.getDrawable(getResources(), R.drawable.white_bg, null)
        tab2.background=null
        tab1.setTextColor(resources.getColor(R.color.white))
        tab2.setTextColor(resources.getColor(R.color.main_cl))
    }
    private fun intab2() {
        tab1.background =null
        tab2.background = ResourcesCompat.getDrawable(getResources(), R.drawable.leve_tab1, null)
        tab1.setTextColor(resources.getColor(R.color.main_cl))
        tab2.setTextColor(resources.getColor(R.color.white))
    }

    override fun initData() {
        super.initData()


    }

    //待我审批fragment组
    fun getApprovalFragments(): MutableList<Fragment> {
        val fragmentArrayList = ArrayList<Fragment>()
//        fragmentArrayList.add(PendingActivity())//待审批
//        fragmentArrayList.add(PendingOkFragment())//已审批
//        fragmentArrayList.add(PendingCopyFragment())//抄送
        fragmentArrayList.add(PendingsFragment())//待审批
        fragmentArrayList.add(PendingsFragment())//抄送
        return fragmentArrayList
    }





    override fun closeMvp() {
    }
}

